/*
 * @Author: lijunqing
 * @Date: 2024-04-18 15:57:47
 * @LastEditors: lijunqing
 * @LastEditTime: 2024-04-19 09:17:26
 * @Description:
 */
const http = require("http");
const fs = require("fs");
// 创建一个对应的服务器
const server = http.createServer((req, res) => {
  // 表单数据意味着一个请求体
  // stream流
  const cws = fs.createWriteStream("./tem.png", {
    flags: "a+",
  });
  //   数据量较大的时候 会多次调用req.on
  req.on("data", (data) => {
    console.log(data);
    cws.write(data);
  });

  req.on("end", () => {
    console.log("文件上传成功");
    res.end("文件上传成功~");
  });
});

// 开启一个服务器端口 1024 - 66535
server.listen("8000", () => {
  console.log("服务器开启成功");
});
